package net.cloudcodex.client.campaign.view.panel;

import net.cloudcodex.client.campaign.view.CampaignsView.Message;
import net.cloudcodex.client.widgets.CampaignAvatar;

import com.google.gwt.event.dom.client.HasKeyDownHandlers;
import com.google.gwt.event.dom.client.HasKeyUpHandlers;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.TextBox;

public class CampaignInfosPanel extends HorizontalPanel {

	private Message message;

	private String icon;
	private String name;
	private String game;

	private FlowPanel rightPanel = new FlowPanel();
	private FlowPanel leftPanel = new FlowPanel();
	private Label nameLbl = new Label();
	private Label gameLbl = new Label();
	private Label iconLbl = new Label();
	private TextBox nameTbx = new TextBox();
	private TextBox gameTbx = new TextBox();
	private TextBox iconTbx = new TextBox();
	private CampaignAvatar avatar = new CampaignAvatar();

	public CampaignInfosPanel() {
		// leftPanel.setWidth("50%");
		// rightPanel.setWidth("50%");
		HorizontalPanel namePnl = new HorizontalPanel();
		HorizontalPanel gamePnl = new HorizontalPanel();
		HorizontalPanel iconPnl = new HorizontalPanel();
		namePnl.add(nameLbl);
		namePnl.add(nameTbx);
		gamePnl.add(gameLbl);
		gamePnl.add(gameTbx);
		
		nameTbx.setHeight("20px");

		leftPanel.add(namePnl);
		leftPanel.add(gamePnl);

		iconPnl.add(iconLbl);
		iconPnl.add(iconTbx);
		iconPnl.add(avatar);

		rightPanel.add(iconPnl);

		this.add(leftPanel);
		this.add(rightPanel);

	}

	public void setMessage(Message message) {
		this.message = message;
	}

	public void addCampaignInfos(String name, String icon, String game) {
		nameTbx.setText(name);
		gameTbx.setText(game);
		iconTbx.setTitle("icon");
		nameTbx.setTitle("name");
		gameTbx.setTitle("game");
		iconTbx.setText(icon);
		avatar.initComponent(icon, name, false);
		avatar.resize("30", "30");
	}

	public void initComponent() {
		nameLbl.setText(message.getNameLbl());
		gameLbl.setText(message.getGameLbl());
		iconLbl.setText(message.getIconLbl());

	}

	public HasKeyDownHandlers getNameTextBoxKeyDown() {
		return nameTbx;
	}

	public HasKeyDownHandlers getGameTextBoxKeyDown() {
		return gameTbx;
	}

	public HasKeyDownHandlers getIconTextBoxKeyDown() {
		return iconTbx;
	}

	public HasKeyUpHandlers getNameTextBoxKeyUp() {
		return nameTbx;
	}

	public HasKeyUpHandlers getGameTextBoxKeyUp() {
		return gameTbx;
	}

	public HasKeyUpHandlers getIconTextBoxKeyUp() {
		return iconTbx;
	}

	public String getCampaignName() {
		return nameTbx.getText();
	}

	public String getCampaignGame() {
		return gameTbx.getText();
	}

	public String getCampaignIcon() {
		return iconTbx.getText();
	}

	public void clearView() {
		nameTbx.setText("");
		gameTbx.setText("");
		iconTbx.setText("");
	}

}
